/*
 *  Copyright (C) 2010 Glauco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.components.managers;

import java.util.Properties;
import javax.swing.JComponent;
import javax.swing.JTextField;
import org.balisunrise.swing.components.util.BaliComponentFocusListener;

/**
 *  Utilizatário para construção dos componentes do ComponentManager.
 * @author Glauco
 */
public class ManagerUtil {

    /**
     * Lê e atribui propriedades a um JComponent.
     *
     * Unificar com PropertyReader em PropertyUtil.
     * @param component
     * @param p
     */
    public static void setProperties(JComponent component, Properties p){

        /*  p.put("insertable", c.insertable());
            p.put("updatable", c.updatable());
            p.put("nullable", c.nullable());
            p.put("length", c.length());
            p.put("precision", c.precision());
            p.put("scale", c.scale());
        */

        String aux = p.getProperty("enabled");
        if(aux != null){
            component.setEnabled(Boolean.parseBoolean(aux));
        }

        // TODO: rever, percorrer as propriedades diferentes das propriedades
        
    }

    public static JTextField createJTextField(Properties p, int length,
            DocumentType documentType){
        
        //throw new UnsupportedOperationException("Not Yet");

        if(p!= null)
            try{
                Object o = p.get("length");
                length = (Integer) o;
            } catch(Exception e){}

        JTextField aux = new JTextField(length);

        aux.addFocusListener(new BaliComponentFocusListener());

        return aux;

    }

    /**
     * Tipo de Documentos suportados.
     */
    public enum DocumentType{
        TEXT,
        UPPER_TEXT,
        NUMBER,
        DECIMAL,
        NEGATIVES_NUMBER,
        NEGATIVES_DECIMAL
    }
}
